package com.cea.papyrus.core.commands;

import com.cea.papyrus.diagraminterchange2.di2.GraphElement;

/**
 * this command is used to add semantic Child to a Graph Element
 * ex Port with a class
 *
 */
public class Di2SemanticChildAddCommand extends Di2WithoutUMLAddCommand {

	/**the semantic child**/
	protected GraphElement semanticParent;
	/** the old semantic graphelement of the childreen**/
	protected GraphElement oldSemanticParent;
	
	/**
	 * create a command to add a semanticChild to a graphelement
	 * @param childGe the semantic child that we want to add
	 * @param parent the real graphElement parent
	 * @param semanticParent the semantic parent of the child
	 */
	public Di2SemanticChildAddCommand(GraphElement childGe,
			GraphElement parent,GraphElement semanticParent) {
		super(childGe, parent,null);
		this.semanticParent=semanticParent;
		oldSemanticParent=(GraphElement)childGe.getSemanticParent();
		
	}
	/**
	 * {@inheritDoc}
	 */
	public boolean canExecute() {
		return nh.canCreateGraphElement(this.newParentGE);
	}

	/**
	 * {@inheritDoc}
	 */
	public void execute(){
		childGe.setSemanticParent(semanticParent);
		nh.addGraphElement(this.childGe, this.newParentGE);
		
	}

	/**
	 * {@inheritDoc}
	 */
	public void redo(){
		childGe.setSemanticParent(semanticParent);
		nh.addGraphElement(this.childGe,this.newParentGE);
		
	}

	/**
	 * {@inheritDoc}
	 */
	public void undo(){
		childGe.setSemanticParent(oldSemanticParent);
		//nh.addGraphElement(this.childGe, this.oldParentGE);
		nh.removeGraphElement(this.childGe, this.newParentGE);
	}	
	
}
